﻿package rd.hardcore.selector 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import rd.hardcore.sampler.PadEvent;
	
	/**
	 * ...
	 * @author Thibault Perret
	 */
	public class SelectItem extends Sprite
	{
		
		/*	V A R	*/
		public var label				: String;
		public var mediaPath			: String;
		
		public var highlight			: Sprite;
		public var tf					: TextField
		
		public function SelectItem() 
		{
			highlight.alpha = 0;
			buttonMode = true;
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.REMOVED_FROM_STAGE, destroy);
			
			tf.text = label;
			
			addEventListener(MouseEvent.MOUSE_OVER, handleOver);
			addEventListener(MouseEvent.MOUSE_OUT, handleOut);
			addEventListener(MouseEvent.CLICK, handleClick);
		}
		
		private function handleClick(e:MouseEvent):void 
		{
			dispatchEvent(new PadEvent(PadEvent.ITEM_SELECTED, mediaPath, label, true));
		}
		
		private function handleOut(e:MouseEvent):void 
		{
			highlight.alpha = 0;
		}
		
		private function handleOver(e:MouseEvent):void 
		{
			highlight.alpha = 1;
		}
		
		private function destroy(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, destroy);
			
		}
		
	}

}